/**
 * @file {同步 偏贴后工位数据
 */
 'use strict'

 const PiantieBase = require('./base');

 class SynchronizePiantiehou  extends PiantieBase {

    currentPanelID = null // 记录当前的panel_id

    constructor (panel,sequelize_source, sequelize_aim, stationName, mujian) {
        super(panel, sequelize_source, sequelize_aim, stationName, mujian);
    }
    /**
     * 初始化参数
     * @param {string} panel 表的模型对象
     * @param {Sequeliz} sequelize_source 源表的sequelize实例
     * @param {Sequeliz} sequelize_aim 目标表的sequelize实例
     * @param {string} stationName 工站名（便于日志区分）
     * @returns
     */
    static getInstance (panel, sequelize_source, sequelize_aim, stationName, mujian) {
        return SynchronizePiantiehou.instance ?  SynchronizePiantiehou.instance : new SynchronizePiantiehou(panel, sequelize_source, sequelize_aim, stationName, mujian);
    }
    /**
     * 获取最新的panel信息
     */
    async getNewsPanel () {
        let panel_id = await this.PanelPiantie.getLatestPanelFromSource(this.sequelize_source);
        if (this.currentPanelID === panel_id) return;
        this.currentPanelID = panel_id;
        return this.currentPanelID;
    }
    /**
     * 根据panel获取全部信息
     * @param {String} panel_id
     */
   async getNewstInfoByPanelId (panel_id) {
       let panel_info = await this.handPanelInfo(panel_id);
       let job_info = await this.handJobInfo(panel_id);
       let flaw_info = await this.handFlawInfo(panel_id);
       let flaw_filter_info = await this.handFlawFilterinfo(panel_id);
       let stations = flaw_filter_info.map((item) => {
           return {
                station_id:item.station_id,
                station_name:item.station_name
           }
       })
       return {
            panel_info,
            job_info,
            flaw_info,
            flaw_filter_info,
            stations
       }
    }
 }

 module.exports = SynchronizePiantiehou;